/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package backup

import (
	"github.com/spf13/cobra"
	"satellite/app/backup"
	"satellite/pkg/errorx"
	"time"
)

var Cmd = backupCmd

// backupCmd represents the backupCmd command
var backupCmd = &cobra.Command{
	Use:   "backup",
	Short: "操作mgr的backup资源",
	Long:  `操作mgr的backup资源`,
	Run: func(cmd *cobra.Command, args []string) {
		_ = cmd.Help()
	},
}

var (
	baseOption = new(backup.BaseOption)
	base       = backup.NewBase(baseOption)
)

func init() {
	backupCmd.Flags().StringVarP(&baseOption.Name, "name", "", "", "资源名称")
	backupCmd.Flags().StringVarP(&baseOption.Namespace, "namespace", "n", "", "资源所在命名空间")
	backupCmd.Flags().DurationVarP(&baseOption.Timeout, "timeout", "", 10*time.Second, "资源超时")
	backupCmd.Flags().StringVarP(&baseOption.Version, "version", "v", "v1", "资源版本,支持[v1,v1alpha1(v1a1)]")
	createCmd.Flags().AddFlagSet(backupCmd.Flags())
	showCmd.Flags().AddFlagSet(backupCmd.Flags())
}

func Args(cmd *cobra.Command, args []string) error {
	if baseOption.Name == "" && len(args) == 0 {
		return errorx.MissNameErr
	}
	if baseOption.Name == "" {
		baseOption.Name = args[0]
	}
	if baseOption.Version != "v1" && baseOption.Version != "v1a1" && baseOption.Version != "v1alpha1" {
		return backup.ErrOfInvalidVersion
	}
	baseOption.Fill()
	return nil
}
